// 本地存储工具

const TOKEN_KEY = 'medmoe_token';
const USER_KEY = 'medmoe_user';
const SESSIONS_KEY = 'medmoe_sessions';

// Token 管理
export const TokenManager = {
  setToken(token: string) {
    localStorage.setItem(TOKEN_KEY, token);
  },
  
  getToken(): string | null {
    return localStorage.getItem(TOKEN_KEY);
  },
  
  removeToken() {
    localStorage.removeItem(TOKEN_KEY);
  }
};

// 用户信息管理
export const UserStorage = {
  setUser(user: any) {
    localStorage.setItem(USER_KEY, JSON.stringify(user));
  },
  
  getUser(): any | null {
    const user = localStorage.getItem(USER_KEY);
    return user ? JSON.parse(user) : null;
  },
  
  removeUser() {
    localStorage.removeItem(USER_KEY);
  }
};

// 会话数据管理
export const SessionStorage = {
  setSessions(sessions: any[]) {
    localStorage.setItem(SESSIONS_KEY, JSON.stringify(sessions));
  },
  
  getSessions(): any[] {
    const sessions = localStorage.getItem(SESSIONS_KEY);
    return sessions ? JSON.parse(sessions) : [];
  },
  
  removeSessions() {
    localStorage.removeItem(SESSIONS_KEY);
  },
  
  // 清除所有存储数据
  clearAll() {
    TokenManager.removeToken();
    UserStorage.removeUser();
    this.removeSessions();
  }
};